package com.hotel.BL;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.EntityName;
import com.Util;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.CompositeFilterOperator;
import com.google.appengine.api.datastore.Query.Filter;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.FilterPredicate;
//import com.google.appengine.api.datastore.Query.SortDirection;

import com.google.appengine.api.datastore.Query.SortDirection;

import data.POS;
import data.POSCategory;
import data.POSItem;
import data.POSKitchen;
import data.POSTax;
import data.POSUnit;

public class POSItemLogic extends AbstractBL {
	public POSItemLogic(HttpServletRequest req,HttpServletResponse resp){
		this.req = req;
		this.resp = resp;
	}
	public List<POSItem> GeneratePOSItem(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		list.addAll(GenSnack(hotelId));
		list.addAll(GenBeverage(hotelId));
		list.addAll(GeniCoffee(hotelId));
		list.addAll(GenSteakSaladSoup(hotelId));
		list.addAll(GenDrink(hotelId));
		list.addAll(GenExtra(hotelId));
		list.addAll(GenEmp(hotelId));
		return list;
	}
	private List<POSItem> GenSnack(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		POSTaxLogic taxLogic = new POSTaxLogic(req,resp);
		
		POSKitchen iCoffeeTable = kitchenLogic.GetPOSKitchen(hotelId, "iCoffee Table");
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POSUnit piece = unitLogic.GetPOSUnit(hotelId, "Piece");
		POSTax vat = taxLogic.GetPOSTax(hotelId, "Vat");
		POSTax ServiceCharge = taxLogic.GetPOSTax(hotelId,"Service Charge");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iCoffee");
		
		POSCategory snack = catLogic.GetPOSCategory(pos.getId(), "Snack");
		if(GetPOSItemFromTitle(snack.getPOSId(),"Hanami+",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Hanami+");
			item.setProductId("SN01");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Tasto+=",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Tasto+=");
			item.setProductId("SN02");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat,ServiceCharge));
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Peanuts",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Peanuts");
			item.setProductId("SN03");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"COPP cereals",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("COPP cereals");
			item.setProductId("SN04");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Koh Kae",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Koh Kae");
			item.setProductId("SN05");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"iKong Kang",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("iKong Kang");
			item.setProductId("SN06");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(50.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Pocky",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Pocky");
			item.setProductId("SN07");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(20.0);
			item.setUnit(piece);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Mama Cup",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Mama Cup");
			item.setProductId("SN08");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(20.0);
			item.setUnit(piece);
			list.add(item);
		}
		if(GetPOSItemFromTitle(snack.getPOSId(),"Dentyne Gum",Long.toString(snack.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(snack.getPOSId());
			item.setTitle("Dentyne Gum");
			item.setProductId("SN09");
			item.setCategory(snack);
			item.setKitchen(iCoffeeTable);
			item.setPrice(15.0);
			item.setUnit(piece);
			list.add(item);
		}
		return list;
	}
	private List<POSItem> GenBeverage(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		
		POSKitchen iCoffeeTable = kitchenLogic.GetPOSKitchen(hotelId, "iCoffee Table");
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POSUnit bottle = unitLogic.GetPOSUnit(hotelId, "Bottle");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iCoffee");
		
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(), "Beverage");
		if(GetPOSItemFromTitle(cat.getPOSId(),"Smirnoff",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Smirnoff");
			item.setProductId("B01");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(80.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Ice",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Ice");
			item.setProductId("B02");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(15.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Soda",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Soda");
			item.setProductId("B03");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(15.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Water",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Water");
			item.setProductId("B04");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(10.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Heineken",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Heineken");
			item.setProductId("B05");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(60.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon");
			item.setProductId("B06");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(60.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Oisshi",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Oisshi");
			item.setProductId("B07");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(25.0);
			item.setUnit(bottle);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Soft Drink",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Soft Drink");
			item.setProductId("B08");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(20.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Lipton",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Lipton");
			item.setProductId("B09");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(20.0);
			item.setUnit(unit);
			list.add(item);
		}
		return list;
	}	
	private List<POSItem> GeniCoffee(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		
		POSKitchen iCoffeeTable = kitchenLogic.GetPOSKitchen(hotelId, "iCoffee Table");
		POSUnit cup = unitLogic.GetPOSUnit(hotelId, "Cup");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iCoffee");
		
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(), "iCoffee");
		if(GetPOSItemFromTitle(cat.getPOSId(),"Ice Milk",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Ice Milk");
			item.setProductId("IC01");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(50.0);
			item.setUnit(cup);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Lemon Ice Tea",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Lemon Ice Tea");
			item.setProductId("IC02");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(40.0);
			item.setUnit(cup);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Apple Ice Tea",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Apple Ice Tea");
			item.setProductId("IC03");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(40.0);
			item.setUnit(cup);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"iPunch",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("iPunch");
			item.setProductId("IC04");
			item.setCategory(cat);
			item.setKitchen(iCoffeeTable);
			item.setPrice(60.0);
			item.setUnit(cup);
			list.add(item);
		}
		return list;
	}
	private List<POSItem> GenSteakSaladSoup(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		
		POSKitchen iChickKitchen = kitchenLogic.GetPOSKitchen(hotelId, "iChic Kitchen");
		
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iChic");
		
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(), "Steak,Salad,Soup");
		if(GetPOSItemFromTitle(cat.getPOSId(),"Vegetable cream soup",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Vegetable cream soup");
			item.setProductId("S101");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(59.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Mushroom cream soup",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Mushroom cream soup");
			item.setProductId("S102");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(59.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Egg salad",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Egg salad");
			item.setProductId("S103");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(79.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Fried chicken salad",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Fried chicken salad");
			item.setProductId("S104");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(99.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Fried pork salad",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Fried pork salad");
			item.setProductId("S105");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(99.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Crispy fish steak",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Crispy fish steak");
			item.setProductId("F106");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(159.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Black pepper pork steak",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Black pepper pork steak");
			item.setProductId("F107");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(159.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Pork rib steak",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Pork rib steak");
			item.setProductId("F108");
			item.setCategory(cat);
			item.setKitchen(iChickKitchen);
			item.setPrice(179.0);
			item.setUnit(unit);
			list.add(item);
		}
		return list;
	}
	private List<POSItem> GenDrink(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		POSTaxLogic taxLogic = new POSTaxLogic(req,resp);
		
		POSKitchen iBar = kitchenLogic.GetPOSKitchen(hotelId, "iBar");
		
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POSTax vat = taxLogic.GetPOSTax(hotelId, "Vat");
		POSTax ServiceCharge = taxLogic.GetPOSTax(hotelId,"Service Charge");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iChic");
		
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(), "Drink");
		if(GetPOSItemFromTitle(cat.getPOSId(),"Root Beer Floated",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Root Beer Floated");
			item.setProductId("D001");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(59.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Juice Frappe with Alcohol+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Juice Frappe with Alcohol+");
			item.setProductId("D002");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(59.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Cheer 630ml Package+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Cheer 630ml Package+");
			item.setProductId("D003");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(170.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Cheer 630 ml",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Cheer 630 ml");
			item.setProductId("D004");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Red",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Red");
			item.setProductId("D005");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon White",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon White");
			item.setProductId("D006");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Black",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Black");
			item.setProductId("D007");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Green",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Green");
			item.setProductId("D008");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Blue+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Blue+");
			item.setProductId("D009");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Yellow+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Yellow+");
			item.setProductId("D010");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Azure+=",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Azure+=");
			item.setProductId("D011");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat,ServiceCharge));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Blond+=",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Blond+=");
			item.setProductId("D012");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat,ServiceCharge));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Bazaar+=",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Bazaar+=");
			item.setProductId("D013");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat,ServiceCharge));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Capri=",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Capri=");
			item.setProductId("D014");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(ServiceCharge));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Pink+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Pink+");
			item.setProductId("D015");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Coral+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Coral+");
			item.setProductId("D016");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Navy+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Navy+");
			item.setProductId("D017");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Copper+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Copper+");
			item.setProductId("D018");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Cyan+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Cyan+");
			item.setProductId("D019");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Full Moon Peach+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Full Moon Peach+");
			item.setProductId("D020");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Spy classic",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Spy classic");
			item.setProductId("D021");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(60.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Smirnoff lemon",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Smirnoff lemon");
			item.setProductId("D022");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(80.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Coke",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Coke");
			item.setProductId("D023");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(25.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Sprite",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Sprite");
			item.setProductId("D024");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(25.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Soda",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Soda");
			item.setProductId("D025");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(25.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Leo",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Leo");
			item.setProductId("D026");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(80.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Red Label 70cl",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Red Label 70cl");
			item.setProductId("D027");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(900.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"Red Label 70cl+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Red Label 70cl+");
			item.setProductId("D027");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(900.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		return list;
	}
	private List<POSItem> GenExtra(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		POSTaxLogic taxLogic = new POSTaxLogic(req,resp);
		
		POSKitchen iBar = kitchenLogic.GetPOSKitchen(hotelId, "iBar");
		
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POSTax vat = taxLogic.GetPOSTax(hotelId, "Vat");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iChic");
		
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(), "Extra");
		if(GetPOSItemFromTitle(cat.getPOSId(),"White Moon Party 1,000",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("White Moon Party 1,000");
			item.setProductId("E001");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(1000.0);
			item.setUnit(unit);
			list.add(item);
		}
		if(GetPOSItemFromTitle(cat.getPOSId(),"White Moon Party 1,000+",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("White Moon Party 1,000+");
			item.setProductId("E001");
			item.setCategory(cat);
			item.setKitchen(iBar);
			item.setPrice(1000.0);
			item.setUnit(unit);
			item.setTax(Arrays.asList(vat));
			list.add(item);
		}
		return list;
	}
	private List<POSItem> GenEmp(long hotelId){
		List<POSItem> list = new ArrayList<POSItem>();
		POSCategoryLogic catLogic = new POSCategoryLogic(req,resp);
		POSKitchenLogic kitchenLogic = new POSKitchenLogic(req,resp);
		POSUnitLogic unitLogic = new POSUnitLogic(req,resp);
		
		POSKitchen iChic = kitchenLogic.GetPOSKitchen(hotelId, "iChic Kitchen");
		
		POSUnit unit = unitLogic.GetPOSUnit(hotelId, "Unit");
		POS pos=new POSLogic(req,resp).GetPOS(hotelId,"iChic");
		
		POSCategory employeeCat = catLogic.GetPOSCategory(pos.getId(), "Employee's Food");
		POSCategory cat = catLogic.GetPOSCategory(pos.getId(),"Omlette",employeeCat.getId());
		if(GetPOSItemFromTitle(cat.getPOSId(),"Omlette",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(cat.getPOSId());
			item.setTitle("Omlette");
			item.setProductId("Emp001");
			item.setCategory(cat);
			item.setKitchen(iChic);
			item.setPrice(10.0);
			item.setUnit(unit);
			list.add(item);
		}
		
		if(GetPOSItemFromTitle(employeeCat.getPOSId(),"RawFish",Long.toString(cat.getId())) == null)
		{
			POSItem item = new POSItem();
			item.setHotelId(hotelId);
			item.setPOSId(employeeCat.getPOSId());
			item.setTitle("RawFish");
			item.setProductId("Emp002");
			item.setCategory(employeeCat);
			item.setKitchen(iChic);
			item.setPrice(10.0);
			item.setUnit(unit);
			list.add(item);
		}
		
		return list;
	}
	
	public POSItem GetPOSItem(long id)
	{
		Key key = KeyFactory.createKey(EntityName.POSItem, id);
		try {
			Entity lang = datastore.get(key);
			POSItem c = new POSItem();
			c.setEntity(lang);
			return c;
		} catch (EntityNotFoundException e) {
			return null;
		}
	}
	
	public POSItem GetPOSItem(Entity entity)
	{
		if(entity == null) return null;
		POSItem item = new POSItem();
		item.setEntity(entity);
		return item;
	}
	
	public POSItem GetPOSItem(long posId,String productId)
	{
		Query q = new Query(EntityName.POSItem);
		
		Filter filterPosId = new FilterPredicate("posId",FilterOperator.EQUAL,posId);
		Filter filterStatus = new FilterPredicate("status",FilterOperator.EQUAL,true);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterProductId = new FilterPredicate("productId",FilterOperator.EQUAL,productId);

		Filter filter = CompositeFilterOperator.and(filterPosId, filterStatus, filterAvaliable,filterProductId);
		
		q.setFilter(filter);
		
		return GetPOSItem(datastore.prepare(q).asSingleEntity());
	}
	
	public POSItem GetPOSItemFromTitle(long posId,String title,String category)
	{
		Query q = new Query(EntityName.POSItem);

		Filter filterPosId = new FilterPredicate("posId",FilterOperator.EQUAL,posId);
		Filter filterStatus = new FilterPredicate("status",FilterOperator.EQUAL,true);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterTitle = new FilterPredicate("title",FilterOperator.EQUAL,title);
		Filter filterCategory = new FilterPredicate("category",FilterOperator.EQUAL,category);

		Filter filter = CompositeFilterOperator.and(filterPosId, filterStatus, filterAvaliable,filterTitle,filterCategory);
		
		q.setFilter(filter);
		
		return GetPOSItem(datastore.prepare(q).asSingleEntity());
	}
	
	public List<POSItem> GetPOSItemList(List<Entity> entities)
	{
		List<POSItem> list = new ArrayList<POSItem>();
		if(entities != null)
		for(Entity e : entities)
		{
			POSItem a = new POSItem();
			a.setEntity(e);
			list.add(a);
		}
		return list;
	}

	public List<POSItem> GetAllPOSItemInPOS(long hotelId,long posId){
		Query q = new Query(EntityName.POSItem);
		Filter filterPOSid = new FilterPredicate("posId",FilterOperator.EQUAL,posId);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filter = CompositeFilterOperator.and(filterPOSid, filterAvaliable);
		q.setFilter(filter);
		
		return GetPOSItemList(datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()));
	}
	
	public POSItem UpdatePOSItem(POSItem item)
	{
		Key key = datastore.put(item.getEntity());
		item.setId(key.getId());
		item.setKey(key);
		return item;
	}
	
	public List<POSItem> GetAllPOSItemByCate(long hotelId, String cateId)
	{
		Query q = new Query(EntityName.POSItem);
		
		Filter filterHotel = new FilterPredicate("hotelId",FilterOperator.EQUAL,hotelId);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterCategoryId = new FilterPredicate("category",FilterOperator.EQUAL,cateId);
		Filter filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterCategoryId);
		
		q.setFilter(filter);
		
		return GetPOSItemList(datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()));
	}
	
	public List<POSItem> GetAllPOSItem4AdminLimit(long hotelId,long offset,long line, String cateId,long posId)
	{
		Query q = new Query(EntityName.POSItem);
		Filter filterHotel = new FilterPredicate("hotelId",FilterOperator.EQUAL,hotelId);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterposId = new FilterPredicate("posId",FilterOperator.EQUAL,posId);
		Filter filter = null;
		if(cateId.equals("0")){
			if(posId==0){
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable);
			}else{
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterposId);
			}
		}else{
			if(posId==0){
				Filter filterCategoryId = new FilterPredicate("category",FilterOperator.EQUAL,cateId);
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterCategoryId);
			}else{
				Filter filterCategoryId = new FilterPredicate("category",FilterOperator.EQUAL,cateId);
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterCategoryId,filterposId);
			}
			
		}
		q.setFilter(filter);
		return GetPOSItemList(datastore.prepare(q).asList(FetchOptions.Builder.withLimit((int) line).offset((int)offset)));
	}
	
	public List<POSItem> GetAllPOSItem4Admin(long hotelId,String cateId,long posId)
	{
		Query q = new Query(EntityName.POSItem);
		Filter filterHotel = new FilterPredicate("hotelId",FilterOperator.EQUAL,hotelId);
		Filter filterAvaliable = new FilterPredicate("avaliable",FilterOperator.EQUAL,true);
		Filter filterposId = new FilterPredicate("posId",FilterOperator.EQUAL,posId);
		Filter filter = null;
		if(cateId.equals("0")){
			if(posId==0){
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable);
			}else{
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterposId);
			}
			
		}else{
			if(posId==0){
				Filter filterCategoryId = new FilterPredicate("category",FilterOperator.EQUAL,cateId);
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterCategoryId);
			}else{
				Filter filterCategoryId = new FilterPredicate("category",FilterOperator.EQUAL,cateId);
				filter = CompositeFilterOperator.and(filterHotel, filterAvaliable,filterCategoryId,filterposId);
			}
			
		}
		q.setFilter(filter);
		return GetPOSItemList(datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()));
	}	
	
	public POSItem AddPOSUnit(long id,long pospoint,String title,String idproduct,
			String favourite,String categoryproduct,Double priceproduct,
			String unitproduct,String taxuse,String cateId,String description) throws EntityNotFoundException{
		POSItem a = new POSItem();
//		a.setDisplayId(GetMaxPOSItemDisplayId(id)+1);
		a.setHotelId(id);
		a.setPOSId(pospoint);
		a.setTitle(title);
		a.setProductId(idproduct);
		if(favourite.equals("true"))
			a.setFavourite(GetMaxPOSItemFavId(id)+1);
		else
			a.setFavourite(0);
		a.setCategoryString(categoryproduct);
		a.setPrice(priceproduct);
		a.setUnitString(unitproduct);
		a.setTaxString(taxuse);
		a.setCategoryString(cateId);
		a.setDescription(description);
		a.setAvaliable(true);
		a.setStatus(true);
		Key k = datastore.put(a.getEntity());
		a.setId(k.getId());
		a.setKey(k);

		return a;
	}
	
	public POSItem EditPOSItem(long id,long pospoint,String title,String idproduct,
			String favourite,String categoryproduct,Double priceproduct,
			String unitproduct,String taxuse,String cateId,String description) throws EntityNotFoundException{
		long hotelId = 1;
		HttpSession session = req.getSession(true);
		if (session.getAttribute("hotelId") != null)
			hotelId = (Long) session.getAttribute("hotelId");

		POSItem a = GetPOSItem(id);
		a.setPOSId(pospoint);
		a.setTitle(title);
		a.setProductId(idproduct);
		if(favourite.equals("true"))
			a.setFavourite(GetMaxPOSItemFavId(hotelId)+1);
		else
			a.setFavourite(0);
		a.setCategoryString(categoryproduct);
		a.setPrice(priceproduct);
		a.setUnitString(unitproduct);
		a.setTaxString(taxuse);
		a.setCategoryString(cateId);
		a.setDescription(description);
		a.setAvaliable(true);
		a.setStatus(true);
		
		Key k = datastore.put(a.getEntity());
		a.setId(k.getId());
		a.setKey(k);

		return a;
	}
	
	public POSItem ChangeStatus(long amenId) throws EntityNotFoundException{
		
		POSItem a = GetPOSItem(amenId);
		if(a.isStatus() == true){
			a.setStatus(false);
		}else if(a.isStatus() == false){
			a.setStatus(true);
		}
		 
		Key k = datastore.put(a.getEntity());
		a.setId(k.getId());
		a.setKey(k);

		return a;
	}
	
	public POSItem DeletePOSItem(long itemId) throws EntityNotFoundException{
		POSItem a = GetPOSItem(itemId);
		a.setAvaliable(false);
		a.setStatus(false);
		Key k = datastore.put(a.getEntity());
		a.setId(k.getId());
		a.setKey(k);
		return a;
	}
	
	public List<HashMap<String,Object>> CalEachTax(double priceWithoutTax,List<POSTax> tax,double discount,long amount,HttpSession session){
		boolean isIncludeTax = (Boolean)session.getAttribute("isIncludetax");
		return CalEachTax(priceWithoutTax, tax, discount, amount, isIncludeTax);
	}
	
	public List<HashMap<String,Object>> CalEachTax(double priceWithoutTax,List<POSTax> tax,double discount,long amount,boolean includeTax){
		List<HashMap<String,Object>> hashTax = new ArrayList<HashMap<String,Object>>();
		if(tax!=null){
			double perc = 0;
			double fix = 0;
			for(POSTax taxItem:tax)
				if(taxItem.isAvaliable() && taxItem.isPercent())
					perc += taxItem.getCurrencyValue();
				else if(taxItem.isAvaliable() && !taxItem.isPercent())
					fix += taxItem.getCurrencyValue();
			HashMap<String,Object> calTax = Util.customCalTax(priceWithoutTax, perc, fix, discount, amount, includeTax);
			double totalPerc = (Double) calTax.get("totalPercTax");
			
			for(POSTax taxItem:tax)
				if(taxItem.isAvaliable() && taxItem.isPercent()){
					HashMap<String,Object> h = new HashMap<String,Object>();
					h.put("POSTaxId", taxItem.getId());
					h.put("Value", totalPerc * taxItem.getCurrencyValue()/(perc*amount));
					hashTax.add(h);
				}
				else if(taxItem.isAvaliable() && !taxItem.isPercent()){
					HashMap<String,Object> h = new HashMap<String,Object>();
					h.put("POSTaxId", taxItem.getId());
					h.put("Value", taxItem.getCurrencyValue());
					hashTax.add(h);
				}
			return hashTax;
		}
		return hashTax;
	}
	
//	public long GetMaxPOSItemDisplayId(long hotelId)
//	{
//		Query q = new Query(EntityName.POSItem);
//
//		Filter filterHotel = new FilterPredicate("hotelId",
//				FilterOperator.EQUAL, hotelId);
//		q.setFilter(filterHotel).addSort("displayId", SortDirection.DESCENDING);
//
//		List<POSItem> list = GetPOSItemList(datastore.prepare(q).asList(
//				FetchOptions.Builder.withLimit(1)));
//		if(list.size()>0)
//			return list.get(0).getDisplayId();
//		return 0;
//	}
	
	public long GetMaxPOSItemFavId(long hotelId)
	{
		Query q = new Query(EntityName.POSItem);

		Filter filterHotel = new FilterPredicate("hotelId",
				FilterOperator.EQUAL, hotelId);
		Filter filterFav = new FilterPredicate("favourite",
				FilterOperator.NOT_EQUAL, 0);
		Filter filter = CompositeFilterOperator.and(filterHotel ,filterFav);
		q.setFilter(filter).addSort("favourite", SortDirection.DESCENDING);

		List<POSItem> list = GetPOSItemList(datastore.prepare(q).asList(
				FetchOptions.Builder.withLimit(1)));
		if(list.size()>0)
			return list.get(0).getFavourite();
		return 0;
	}
}
